Skip to content

chore/version-management #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Apr 16, 2025
Merged

chore/version-management #122

merged 20 commits into from
Apr 16, 2025

Conversation

g1331
Copy link
Owner

@g1331 g1331 commented Apr 2, 2025

好的,这是将拉取请求摘要翻译成中文的结果:

Sourcery 总结

为项目添加版本管理和信息显示功能,包括版本跟踪、git 信息检索和变更日志生成

新功能:

  • 在机器人状态命令中添加版本信息显示
  • 使用 bump2version 实现版本管理脚本
  • 添加 git 信息检索实用程序
  • 使用 git-cliff 创建自动变更日志生成

增强功能:

  • 改进项目文件中的版本跟踪
  • 添加详细的版本信息检索
  • 创建用于版本管理的实用程序脚本

构建:

  • 使用新的依赖项更新 pyproject.toml
  • 添加 uv 配置以禁用项目安装

杂项:

  • 更新项目配置文件
  • 添加版本管理工具
  • 配置 bump2version 和 git-cliff
Original summary in English

Summary by Sourcery

Add version management and information display functionality to the project, including version tracking, git information retrieval, and changelog generation

New Features:

  • Add version information display in bot status command
  • Implement version management script with bump2version
  • Add git information retrieval utility
  • Create automated changelog generation using git-cliff

Enhancements:

  • Improve version tracking across project files
  • Add detailed version information retrieval
  • Create utility scripts for version management

Build:

  • Update pyproject.toml with new dependencies
  • Add uv configuration to disable project installation

Chores:

  • Update project configuration files
  • Add version management tools
  • Configure bump2version and git-cliff

Copy link
Contributor

sourcery-ai bot commented Apr 2, 2025

## Sourcery 评审者指南

此 Pull Request 引入了使用 `bump2version` 的版本管理,并在 Bot 的状态中显示版本信息。它包括对 `status` 命令的更改,以显示版本、Git 和构建信息,并添加了用于版本 bumping 和检索版本信息的脚本。它还添加了 `bump2version` 和 `tomli` 作为依赖项。

#### 带有版本信息的状态命令的序列图

```mermaid
sequenceDiagram
    participant User
    participant Ariadne (Bot)
    participant core
    participant utils.version_info

    User->>Ariadne (Bot): issues status command
    Ariadne (Bot)->>core: Retrieves runtime information
    Ariadne (Bot)->>utils.version_info: get_full_version_info()
    utils.version_info-->>Ariadne (Bot): version, git_info, b2v_info
    Ariadne (Bot)->>Ariadne (Bot): Formats status message with version info
    Ariadne (Bot)-->>User: Sends status message

版本信息的更新后的类图

classDiagram
    class VersionInfo {
        -version: str
        -git_info: dict
        -b2v_info: dict
        +get_version(): str
        +get_git_info(): dict
        +get_b2v(): dict
        +get_full_version_info(): tuple[str, dict, dict]
    }

    class GitInfo {
        -branch: str
        -commit: str
        -commit_short: str
        -commit_time: str
        -commit_author: str
        -commit_message: str
    }

    class BuildInfo {
        -build_number: str
        -build_date: str
        -build_type: str
    }

    VersionInfo -- GitInfo : contains
    VersionInfo -- BuildInfo : contains
Loading

文件级别变更

变更 详情 文件
引入了使用 bump2version 的版本管理,并在 Bot 的状态中显示版本信息。
  • 添加了 bump2versiontomli 作为依赖项。
  • 添加了用于版本 bumping 的 bump.py 脚本。
  • 添加了 version_info.py 以检索版本信息。
  • 修改了 status 命令以包含版本、Git 和构建信息。
  • 使用初始版本更新了 pyproject.toml,并添加了 uv 工具配置。
  • 添加了 CHANGELOG.md 以跟踪更改。
  • 添加了 .bumpversion.cfg 以配置 bump2version
modules/required/status/__init__.py
pyproject.toml
uv.lock
CHANGELOG.md
utils/bump.py
utils/version_info.py
cliff.toml
.bumpversion.cfg
core/__init__.py

提示和命令

与 Sourcery 互动

  • 触发新的审查: 在 Pull Request 上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 通过回复审查评论,要求 Sourcery 从审查评论创建一个 Issue。您也可以回复审查评论并使用 @sourcery-ai issue 从中创建一个 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中的任何位置写入 @sourcery-ai 以随时生成标题。您也可以在 Pull Request 上评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文中的任何位置写入 @sourcery-ai summary 以随时在您想要的位置生成 PR 摘要。您也可以在 Pull Request 上评论 @sourcery-ai summary 以随时(重新)生成摘要。
  • 生成评审者指南: 在 Pull Request 上评论 @sourcery-ai guide 以随时(重新)生成评审者指南。
  • 解决所有 Sourcery 评论: 在 Pull Request 上评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经处理了所有评论并且不想再看到它们,这将非常有用。
  • 驳回所有 Sourcery 审查: 在 Pull Request 上评论 @sourcery-ai dismiss 以驳回所有现有的 Sourcery 审查。如果您想重新开始新的审查,这将特别有用 - 不要忘记评论 @sourcery-ai review 以触发新的审查!
  • 为 Issue 生成行动计划: 在 Issue 上评论 @sourcery-ai plan 以为其生成行动计划。

自定义您的体验

访问您的 仪表板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 Pull Request 摘要、评审者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

```
Original review guide in English

Reviewer's Guide by Sourcery

This pull request introduces version management using bump2version and displays version information in the bot's status. It includes changes to the status command to display version, git, and build information, and adds scripts for version bumping and retrieving version information. It also adds bump2version and tomli as dependencies.

Sequence diagram for status command with version info

sequenceDiagram
    participant User
    participant Ariadne (Bot)
    participant core
    participant utils.version_info

    User->>Ariadne (Bot): issues status command
    Ariadne (Bot)->>core: Retrieves runtime information
    Ariadne (Bot)->>utils.version_info: get_full_version_info()
    utils.version_info-->>Ariadne (Bot): version, git_info, b2v_info
    Ariadne (Bot)->>Ariadne (Bot): Formats status message with version info
    Ariadne (Bot)-->>User: Sends status message
Loading

Updated class diagram for version information

classDiagram
    class VersionInfo {
        -version: str
        -git_info: dict
        -b2v_info: dict
        +get_version(): str
        +get_git_info(): dict
        +get_b2v(): dict
        +get_full_version_info(): tuple[str, dict, dict]
    }

    class GitInfo {
        -branch: str
        -commit: str
        -commit_short: str
        -commit_time: str
        -commit_author: str
        -commit_message: str
    }

    class BuildInfo {
        -build_number: str
        -build_date: str
        -build_type: str
    }

    VersionInfo -- GitInfo : contains
    VersionInfo -- BuildInfo : contains
Loading

File-Level Changes

Change Details Files
Introduces version management using bump2version and displays version information in the bot's status.
  • Adds bump2version and tomli as dependencies.
  • Adds bump.py script for version bumping.
  • Adds version_info.py to retrieve version information.
  • Modifies the status command to include version, git, and build information.
  • Updates pyproject.toml with the initial version and adds a uv tool configuration.
  • Adds CHANGELOG.md to track changes.
  • Adds .bumpversion.cfg to configure bump2version.
modules/required/status/__init__.py
pyproject.toml
uv.lock
CHANGELOG.md
utils/bump.py
utils/version_info.py
cliff.toml
.bumpversion.cfg
core/__init__.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @g1331 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using a dedicated settings file (e.g., settings.toml) instead of environment variables for build information.
  • The bump.py script is a nice addition, but it might be simpler to just use bump2version directly in a Makefile.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 2 issues found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

utils/bump.py Outdated
sys.exit(1)


def run_bumpversion(part, new_version=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider creating a helper function to encapsulate subprocess execution and error handling to avoid repetition across multiple functions like run_bumpversion, update_uv_lock, and generate_changelog, improving code maintainability and readability.

Actionable Recommendation:

Consolidate the repeated subprocess invocations and error handling into a helper function. This centralizes the logic and reduces duplication.

Steps:

  1. Create a helper function:

    def run_command(cmd, success_msg=None, error_msg="命令执行失败"):
        try:
            result = subprocess.run(cmd, capture_output=True, text=True)
            if result.returncode != 0:
                print(f"❌ {error_msg}: {result.stderr}")
                sys.exit(1)
            if success_msg:
                print(success_msg)
            return result.stdout
        except Exception as e:
            print(f"❌ {error_msg}: {e}")
            sys.exit(1)
  2. Refactor run_bumpversion:

    def run_bumpversion(part, new_version=None):
        cmd = ["bump2version"]
        if new_version:
            cmd += ["--new-version", new_version]
        cmd.append(part)
        run_command(cmd, success_msg="✅ 版本号已更新", error_msg="bump2version 执行失败")
        return True
  3. Refactor similar functions (e.g., update_uv_lock, generate_changelog):

    def update_uv_lock():
        if not os.path.exists("uv.lock"):
            print("⚠️ 未找到 uv.lock,跳过")
            return
        run_command(["uv", "lock"], success_msg="✅ uv.lock 已更新", error_msg="uv lock 执行失败")
    
    def generate_changelog(version: str):
        cmd = ["git-cliff", "--tag", f"v{version}", "-o", "CHANGELOG.md"]
        run_command(cmd, success_msg="✅ changelog 已生成", error_msg="changelog 生成失败")

These changes keep all functionality intact while reducing repetitive error handling and subprocess logic.

@@ -0,0 +1,102 @@
import os
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (complexity): Consider using a dedicated version file and relative imports to simplify version information handling and avoid modifying sys.path.

To reduce complexity without reverting functionality, consider removing the temporary sys.path manipulation by placing your version information in a dedicated file within the package. This lets you use a standard relative import and isolates fallback logic. For example:

  1. Create a dedicated version file
    In core/version.py, define:

    __version__ = "1.2.3"  # your current version
  2. Import version info using relative import
    Replace the dynamic sys.path adjustment with a relative import:

    try:
        from core.version import __version__
    except ImportError as e:
        logger.error(f"导入版本信息失败: {e}")
        __version__ = fallback_version()
  3. Isolate fallback logic
    Define a helper for fallback reading:

    def fallback_version() -> str:
        try:
            import tomli
            with open(Path(__file__).parent.parent / "pyproject.toml", "rb") as f:
                data = tomli.load(f)
                return data.get("project", {}).get("version", "0.0.0")
        except Exception as e:
            logger.error(f"读取版本信息失败: {e}")
            return "0.0.0"

This approach eliminates temporary sys.path modifications while keeping functionality intact and simplifying error handling.

utils/bump.py Outdated
return line.split("=")[1].strip()
except Exception as e:
print(f"❌ 读取 .bumpversion.cfg 失败: {e}")
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Remove redundant pass statement (remove-redundant-pass)

Suggested change
pass

utils/bump.py Outdated

def get_base_version(version: str) -> str:
match = re.match(r"\d+\.\d+\.\d+", version)
return match.group(0) if match else version
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Replace m.group(x) with m[x] for re.Match objects (use-getitem-for-re-match-groups)

Suggested change
return match.group(0) if match else version
return match[0] if match else version

Comment on lines +66 to +75
result.update(
{
"branch": repo.active_branch.name,
"commit": commit.hexsha,
"commit_short": commit.hexsha[:7],
"commit_time": str(commit.authored_datetime),
"commit_author": commit.author.name,
"commit_message": commit.message.strip(),
}
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Merge dictionary updates via the union operator (dict-assign-update-to-union)

Suggested change
result.update(
{
"branch": repo.active_branch.name,
"commit": commit.hexsha,
"commit_short": commit.hexsha[:7],
"commit_time": str(commit.authored_datetime),
"commit_author": commit.author.name,
"commit_message": commit.message.strip(),
}
)
result |= {
"branch": repo.active_branch.name,
"commit": commit.hexsha,
"commit_short": commit.hexsha[:7],
"commit_time": str(commit.authored_datetime),
"commit_author": commit.author.name,
"commit_message": commit.message.strip(),
}

@g1331 g1331 force-pushed the chore/version-management branch from 0354d26 to d406e10 Compare April 2, 2025 11:06
@g1331 g1331 force-pushed the chore/version-management branch from a373231 to 79dc111 Compare April 2, 2025 11:49
@g1331 g1331 merged commit 8ecdb1a into v3 Apr 16, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant